package com.yxq.mdt.app.modules.pm.ui;

import android.text.TextUtils;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.yxq.mdt.app.R;
import com.yxq.mdt.app.application.IntentHelper;
import com.yxq.mdt.app.glide.GlideHelper;
import com.yxq.mdt.app.modules.pm.bean.GoodsCommentBean;
import com.yxq.mdt.app.utils.GridSpacingItemDecoration;
import com.yxq.mdt.app.widgets.CircleImageView;

import java.util.List;

/**
 * @author L
 * @time 2019-10-21
 * @describe 商品详情-评论列表
 */
public class GoodsCommentListAdapter extends BaseQuickAdapter<GoodsCommentBean.ListBean, BaseViewHolder> {

    public GoodsCommentListAdapter(int layoutResId, @Nullable List<GoodsCommentBean.ListBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, GoodsCommentBean.ListBean item) {

        helper.setText(R.id.item_tv_name, TextUtils.isEmpty(item.getNickname()) ? "" : item.getNickname());
        GlideHelper.setLoadCirlcleImage(mContext, item.getAvatar_url(), R.mipmap.head_icon, (CircleImageView) helper.getView(R.id.item_iv_avatar));
        helper.setText(R.id.item_tv_content, TextUtils.isEmpty(item.getContent()) ? "" : item.getContent());
        helper.setText(R.id.item_tv_city, "");
        RecyclerView imgRecyclerView = helper.getView(R.id.recyclerView);

        helper.setVisible(R.id.recyclerView, item.getPic_list() != null && item.getPic_list().size() > 0);
        imgRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL));
        GoodsCommentImagesListAdapter goodsCommentImagesListAdapter = new GoodsCommentImagesListAdapter(R.layout.layout_image_item_layout, item.getPic_list());
        imgRecyclerView.setAdapter(goodsCommentImagesListAdapter);
        goodsCommentImagesListAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                IntentHelper.picture(position, item.getPic_list());
            }
        });
        if (imgRecyclerView.getItemDecorationCount() == 0) {
            imgRecyclerView.addItemDecoration(new GridSpacingItemDecoration(3, 8, false));
        }
    }

}
